#include "ring.hpp"

void* Consume(void* argv)
{
  RingQueue<int> *q = (RingQueue<int>*) argv;
  while(true){
    int data = -1;
    q->Pop(data);
    printf("消费者进行消费：%d\n", data);
    usleep(600000);
  }
}

void* Produce(void* argv)
{
  RingQueue<int> *q = (RingQueue<int>*) argv;
  while(true){
    int data = rand() % 100 + 1;
    q->Push(data);
    printf("生产者进行生产：%d\n", data);
    usleep(600000);
  }
}

int main()
{
  srand((unsigned long)time(nullptr));
  pthread_t pro, con;
  RingQueue<int> *q = new RingQueue<int>();
  pthread_create(&pro, nullptr, Produce, (void*)q);
  pthread_create(&con, nullptr, Consume, (void*)q);

  pthread_join(pro, nullptr);
  pthread_join(con, nullptr);

  return 0;
}
